function varargout = TLBusInportDlg(action,varargin)

% TL_BUSINPORT_DLG manages the user interface for TargetLink BusInport block
%
% SYNTAX dlgInfo = TLBusinportDlg('GetDlgInfo');
%   gets dialog info of TargetLink BusInport block
%
%   INPUT ARGUMENTS
%   -/-      
%
%   OUTPUT ARGUMENTS
%   dlgInfo     dialog information contains pageNames etc.
%
% SYNTAX [sheetDims, ctrlPos] = ...
%           TLBusinportDlg('CtrlPositions', pageName, commonGeom, dlgInfo, sheetDims);
%   calculates the control positions of all controls of dialog page: <pageName>
%
%   INPUT ARGUMENTS
%   pageName        name of current page
%   commonGeom      common geometry data
%   dlgInfo         dialog information contains pageNames etc.
%   sheetDims       dimension of sheet
%
%   OUTPUT ARGUMENTS
%   sheetDims       modified dimension of sheet
%   ctrlPos         positions of controls
%
% SYNTAX dlgdata = TLBusinportDlg('Create', pageName, dlgfig, dlgdata);
%   creates all controls of dialog page: <pageName>
%
%   INPUT ARGUMENTS
%   pageName        name of current page
%   dlgfig          figure handle
%   dlgdata         dialog data
%
%   OUTPUT ARGUMENTS
%   dlgdata         modified dialog data
%
% SYNTAX [dlgdata,bModified] = TLBusinportDlg('Manage', pageName, dlgfig, dlgdata, pageAction);
%   manages all actions of dialog page: <pageName>
%
%   INPUT ARGUMENTS
%   pageName        name of current page
%   dlgfig          figure handle
%   dlgdata         dialog data
%   pageAction      modified control of current page
%
%   OUTPUT ARGUMENTS
%   dlgdata         modified dialog data
%   bModified       flag = 1, if dialog data are modified, =0 otherwise
%
% SYNTAX dlgdata = TLBusinportDlg('Update', dlgfig, dlgdata, pageNum);
%   updates all controls of dialog page: <pageNum>
%
%   INPUT ARGUMENTS
%   dlgfig          figure handle
%   dlgdata         dialog data
%   pageNum         number of current page
%
%   OUTPUT ARGUMENTS
%   dlgdata         modified dialog data
%
% SYNTAX TLBusinportDlg('Apply', dlgfig, dlgdata);
%   writes current blockdata to block and DD
%
%   INPUT ARGUMENTS
%   dlgfig      handle for dialog figure
%   dlgdata     dialog data
%
%   OUTPUT ARGUMENTS
%   - / -


% Author(s): D. Andoleit, T. Pietzsch
% $RCSfile: TLBusinportDlg.m $
% $ProjectName: e:/ARC/Components/HostSW/SimulinkBlocksets/TLBlocksets/CommonBlockset/CommonBlockset_SimBlocksUI/Sources/MSrc/project.pj $
% $Revision: 1.10 $
% $Date: 2011/05/13 08:02:36MESZ $
%
% Copyright ?2011 dSPACE GmbH. All rights reserved.


% branch dependend on action
switch action,
    case 'CtrlPositions',
        pageName = varargin{1};
        switch pageName,
            case 'Output',
                % additional input 'excludedCtrls' neccessary for difference between inport and outport
                varargin{6} = {'saturate'};
            case 'RTOS'
                % additional input 'excludedCtrls' neccessary for difference between inport and outport
                varargin{6} = {};
        end

    case 'Create'
        dlgdata  = varargin{3};
        % check, if blockdata fit to expected dialog
        if strcmp(dlgdata.maskType, 'TL_Inport')
            % set block data to default; add effectivescaling
            dlgdata.maskType = 'TL_BusInport';
            effScaling = dlgdata.data.effectivescaling;
            dlgdata.data = tl_get_default_blockdata(dlgdata.maskType);
            dlgdata.data.effectivescaling = effScaling;
        end
        varargin{3} = dlgdata;
        
    case 'Manage'
        pageName   = varargin{1};

        switch pageName
            case 'AUTOSAR'
                % AUTOSAR page
                varargin{5} = 0;     %bIsOutport
        end
        
    case 'Update'
        pageNum   = varargin{3};

        switch pageNum
            case 3
                % RTOS page
                varargin{4} = 0;     %bIsOutport
                
            case 4
                % AUTOSAR page
                varargin{4} = 0;     %bIsOutport
        end
        
    case 'Apply'
        dlgdata = varargin{2};
        if strcmp(get_param(dlgdata.model,'MaskType'), 'TL_Inport')
            % set correct maskType
            set_param(dlgdata.model,'MaskType', 'TL_BusInport')
        end
end

[varargout{1:nargout}] = TLBusportDlg(action, varargin{:});
